// 拦截 表格 页面组件的请求 返回模拟数据
import mockjs from 'mockjs'

// 人员信息数据类
class DataHelper {
    // 构建函数 用于 初始化数据
    constructor() {
        this.datas = mockjs.mock({
            "persons|100": [{
                "key|+1": 1001,
                "id|+1": 1001,
                "name": "@cname",
                "age": "@integer(18,65)",
                "address": "@city"
            }]
        })
    }
    getPerson() {
        let results = this.datas.persons;
        return results
    }
    removerPerson(id) {
        this.datas.persons = this.datas.persons.filter((item) => item.id != id)
    }
}

const dh = new DataHelper()

export default [
    {
        url: /\/persons/,
        method: /get/,
        response: function () {
            return {
                code: 0,
                msg: "获取列表",
                data: dh.getPerson()
            }
        }
    },
    {
        url: /\/persons\/\d+/,
        method: /dlete/,
        response: function (option) {
            let id = option.url.slice(option.url.lastIndexOf('/') + 1)
            dh.removerPerson(id)
            return {
                code: 0,
                msg: "删除列表",
                data: dh.getPerson()
            }
        }
    }
]